package com.mail;


import com.config.EmailConfig;
import com.mail.template.MailTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;


@Component
public class DefaultMailSendService implements MailSendService {

    @Autowired
    private JavaMailSender javaMailSender;

    @Autowired
    private EmailConfig emailConfig;

    @Override
    public boolean send(String email, String code) {
        return sendMail(email, code);
    }

    private boolean sendMail(String email, String code) {
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setFrom(emailConfig.getUsername());
        mailMessage.setTo(email);
        mailMessage.setSubject("注册验证码");//邮件主题
        mailMessage.setText("您的验证码为:"+code);//邮件内容
        javaMailSender.send(mailMessage);
        return true;
    }

}
